﻿using System;
using System.Collections.Generic;
using System.Text;
using Vol;
using IrrKlang;

namespace Voize
{
    internal class CVolume : IVolume
    {

        internal CVolume(VolumeControl vol_control,CInternetStream web_stream)
        {
            m_VolControl = vol_control;
            m_WebStream = web_stream;
        }


        internal void SetSoundHandler(ISound sound_handler)
        {
            m_SoundHandler = sound_handler;
            m_VolControl.SetVolumeHandler(this);

        }

        internal void SetStreamSoundHandler()
        {
            m_VolControl.SetVolumeHandler(this);
        }

        private ISound m_SoundHandler;
        private VolumeControl m_VolControl;
        private bool m_IsMuted = false;
        private CInternetStream m_WebStream;

        #region IVolume Members
        public void SetVolumeLevel(double value)
        {
            if (m_WebStream.IsPlaying)
            {
                m_WebStream.SetVolume((int)value);
            }
            else
            {
                if (value >= 1 && value <= 10)
                {
                    if (m_SoundHandler != null)
                    {
                        float val;
                        val = (float)value / (float)10;
                        m_SoundHandler.Volume = val;
                        m_IsMuted = false;
                    }
                }
            }
        }
        #endregion

        internal void Mute()
        {
            if (m_SoundHandler != null)
            {
                //m_VolControl.AdjustSliderValue(0.0);
                m_SoundHandler.Volume = 0.0F;
                m_IsMuted = true;
            }
        }

        internal float CurrentVolumeLevel
        {
            get { return (float)m_VolControl.CurrentVolumeLevel; }
        }

        internal bool IsMuted
        {
            get { return m_IsMuted; }
        }

        internal ISound SoundHandler
        {
            get { return m_SoundHandler; }
        }
    }
}
